#!/usr/bin/env python
# -*- encoding: utf-8 -*-
"""
@File        :   27. 移除元素.py    
@Contact     :   lhouctcs@163.com
@License     :   MIT
@Time        :   2023/2/1 13:45
@Author      :   lhou 
@Version     :   0.1.0
@Description :
"""
from typing import List


# import lib
class Solution:
    def removeElement(self, nums: List[int], val: int) -> int:
        # 暴力法
        res = 0
        for i in range(len(nums)):
            if nums[i] != val:
                nums[res] = nums[i]
                res += 1
        # nums = nums[:res]
        return res

    def removeElement_2(self, nums: List[int], val: int) -> int:
        # 双指针
        f, s = 0, 0
        num = len(nums)
        while f < num:
            if nums[f] != val:
                nums[s] = nums[f]
                s += 1
            f += 1
        return s
